package com.elonnx.web;

import com.elonnx.entity.Student;
import com.elonnx.service.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

/**
 * 学生列表的Servlet
 * @author 马元
 * @date 2024-07-12
 */
@WebServlet("/student/list")
public class StudentListServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // 查询学生列表
        StudentService studentService = new StudentService();
        List<Student> list = studentService.findList();

        // 转发到页面
        request.setAttribute("studentList", list);
        request.getRequestDispatcher("/studentList.jsp").forward(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doGet(request, response);
    }

}
